home *** CD-ROM | disk | FTP | other *** search
/ 1,000+ Great Games / 1_1000 Games.iso / DOSGAMES / BOGGLE.ZIP / SOURCE.ZIP / TIMER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-03  |  4.8 KB  |  153 lines

  1. /*****************************************************************************
  2. * Program:  TIMER.CPP
  3. * Purpose:  Handles the timer on the bottom of the game board
  4. *****************************************************************************/
  5. #include  "timer.hpp"                 
  6.  
  7.                       
  8. /*****************************************************************************
  9. * Function: TBogTimer
  10. * Parms:    Pointers to parent windows, the game and sound objects
  11. * Purpose:  Instantiate the timer object
  12. * Returns:  Nothing
  13. *****************************************************************************/
  14. TBogTimer::TBogTimer(unsigned long WindowID, IWindow *Parent, 
  15.                      TBogWindow* Game, Sound* pSound)
  16.           : IProgressIndicator(5001, Parent, Parent, IRectangle(), 101, 4, 
  17.               IProgressIndicator::horizontal | IProgressIndicator::alignBottom | IProgressIndicator::homeLeft
  18.               | IProgressIndicator::primaryScale1 | IProgressIndicator::snapToTickMark
  19.               | IProgressIndicator::ribbonStrip | IWindow::visible)
  20. {
  21.    IFont myfont;
  22.  
  23.    game = Game;
  24.    psound = pSound;
  25.  
  26.    //  Set the size of the progress indicator shaft and enable owner draw
  27.    setShaftBreadth(10);
  28.    enableDrawItem();
  29.  
  30.    setTickLength(0,10);
  31.    setTickText(0, IString(0));
  32.  
  33.   //  Set the length and text for the slider's ticks.
  34.   for ( int i=1; i<101; i+=1) 
  35.   {
  36.        if((i % 10) == 0)  
  37.        {
  38.           setTickLength(i,10);
  39.           setTickLength(i-5,5);
  40.           setTickText(i, IString(i));
  41.        }
  42.        else
  43.           setTickLength(i,2);
  44.    }
  45.  
  46. //  Get the pixel offset for pixel 0 to use as a base.
  47.    IPoint base(tickPosition(0));
  48.  
  49. //Set the font for the control
  50.    myfont.setName("Helvetica")
  51.          .setPointSize(8);
  52.  
  53.    setFont((myfont));
  54.  
  55. //Set the colors
  56.    setForegroundColor(IColor::black);
  57.    setBackgroundColor(IColor::darkGray);
  58.  
  59.   IEditHandler::handleEventsFor(this);
  60. }
  61.  
  62. /*****************************************************************************
  63. * Function: ~TBogTimer
  64. * Parms:    none
  65. * Purpose:  destructor
  66. * Returns:  Nothing
  67. *****************************************************************************/
  68. TBogTimer::~TBogTimer()
  69. {
  70. }
  71.  
  72. /*****************************************************************************
  73. * Function: TimerHandler
  74. * Parms:    none
  75. * Purpose:  On every click of the timer,  this gets fired.  Move the 
  76. *           progress indicator and maybe play some sound.
  77. * Returns:  Nothing
  78. *****************************************************************************/
  79. void TBogTimer::TimerHandler()
  80. {
  81.    unsigned long ulOffset;
  82.   
  83. // Play the tick sound
  84.    if(game->GetSoundFlag())
  85.       DosBeep(BEEPFREQ, BEEPDURATION);
  86.    
  87.    ulOffset = armTickOffset();
  88.    if (ulOffset < 100)
  89.       moveArmToTick(++ulOffset);
  90.    else                                //game over
  91.       game->gameOver();
  92. }
  93.  
  94. /*****************************************************************************
  95. * Function: startTimer
  96. * Parms:    none
  97. * Purpose:  Start the timer.  It is my understanding that the destruction
  98. *           of this timer is automatic by the class library but I am not
  99. *           sure.
  100. * Returns:  Nothing
  101. *****************************************************************************/
  102. void TBogTimer::startTimer()
  103. {
  104. //Set the duration based on the settings in the game
  105.    timerDuration = game->GetTickDuration();
  106.  
  107. //Start the timer
  108.    start(new ITimerMemberFn0<TBogTimer>
  109.                  (*this, TBogTimer::TimerHandler), timerDuration);
  110. }
  111.  
  112. /*****************************************************************************
  113. * Function: stopTimer
  114. * Parms:    none
  115. * Purpose:  Stop the timer.  It is my understanding that the destruction
  116. *           of this timer is automatic by the class library but I am not
  117. *           sure.
  118. * Returns:  Nothing
  119. *****************************************************************************/
  120. void TBogTimer::stopTimer()
  121. {
  122.     stop();  // class library function
  123. }
  124.  
  125.  
  126. /*****************************************************************************
  127. * Function: resetTimer
  128. * Parms:    none
  129. * Purpose:  Bring the progress indicator back to its starting state
  130. *           and stop the timer
  131. * Returns:  Nothing
  132. *****************************************************************************/
  133. void TBogTimer::resetTimer()
  134. {
  135. //Stop the timer
  136.    stopTimer();
  137.    
  138. // Set the arm back to zero
  139.    moveArmToTick(0);
  140. }
  141.  
  142.  
  143. /*****************************************************************************
  144. * Function: edit
  145. * Parms:    none
  146. * Purpose:  defined as a virtual function in the class lib so I must
  147. *           declare it here.
  148. * Returns:  Nothing
  149. *****************************************************************************/
  150. Boolean TBogTimer::edit ( IControlEvent& event )
  151. {
  152.    return true;
  153. }